<template>
    <div>
        <div class="info_body">
            <div class="listItm">
                <div class="listFlex main" style="padding-left: 22upx;">
                    <div class="listLeft36">建册医院</div>
                    <div class="listRight">
                        <span class="listCheckT">{{hospital}}</span>
                    </div>
                </div>
            </div>
            <div class="listItm">
                <div class="listFlex main" style="padding-left: 22upx;">
                    <div class="listLeft36">孕妇信息</div>
                    <div class="listRight"></div>
                </div>
            </div>
            <div class="listItm">
                <div class="listFlex main">
                    <div class="listLeft">
                        <span class="mustCheck__content">*</span>孕妇姓名
                    </div>
                    <div class="listRight">
                        <span class="listCheckT">
                            <input
                                type="text"
                                maxlength="10"
                                :disabled="disabled"
                                placeholder-style="color: #999;"
                                class="inputStyle"
                                placeholder="请填写"
                                v-model.trim="userInflist.gravidaInfo.chineseName "
                            />
                        </span>
                    </div>
                </div>
            </div>
            <picker
                class="listItm"
                v-if="array"
                :disabled="disabled"
                @change="cartChange"
                :value="index0"
                range-key="name"
                :range="documentType"
            >
                <div class="listFlex main">
                    <div class="listLeft">
                        <span class="mustCheck__content">*</span>证件类型
                    </div>
                    <div class="listRight" v-if="index0&&documentType[index0]">
                        <span
                            class="listCheckT"
                            v-if="documentType[index0].name"
                        >{{documentType[index0].name}}</span>
                        <span class="weui-cell__ft_in-access"></span>
                    </div>
                    <div class="listRight" v-else>
                        <span class="listCheckT">请选择</span>
                        <span class="weui-cell__ft_in-access"></span>
                    </div>
                </div>
            </picker>
            <div class="listItm">
                <div class="listFlex main">
                    <div class="listLeft">
                        <span class="mustCheck__content">*</span>证件号码
                    </div>
                    <div class="listRight">
                        <span class="listCheckT">
                            <input
                                :disabled="disabled"
                                type="text"
                                maxlength="18"
                                placeholder-style="color: #999;"
                                class="inputStyle"
                                placeholder="请填写"
                                v-model.trim="userInflist.gravidaInfo.idNumber"
                                @blur="inputT3"
                            />
                        </span>
                        <span class="weui-cell__ft_in-access hiddenCom"></span>
                    </div>
                </div>
            </div>
            <picker
                :disabled="disabled"
                :end="endTime"
                class="listItm"
                mode="date"
                @change="birthdayChange"
            >
                <div class="listFlex main">
                    <div class="listLeft">
                        <span class="mustCheck__content">*</span>出生日期
                    </div>
                    <div class="listRight" v-if="userInflist.gravidaInfo.birthday">
                        <span class="listCheckT">{{ issubstring(userInflist.gravidaInfo.birthday) }}</span>
                        <span class="weui-cell__ft_in-access"></span>
                    </div>
                    <div class="listRight" v-else>
                        <span class="listCheckT">请选择</span>
                        <span class="weui-cell__ft_in-access"></span>
                    </div>
                </div>
            </picker>
            <picker
                class="listItm"
                v-if="array"
                :disabled="disabled"
                @change="nationChange"
                :value="index1"
                range-key="name"
                :range="nationality"
            >
                <div class="listFlex main">
                    <div class="listLeft">国籍</div>
                    <div class="listRight" v-if="index1&&nationality[index1]">
                        <span
                            class="listCheckT"
                            v-if="nationality[index1].name"
                        >{{nationality[index1].name}}</span>
                        <span class="weui-cell__ft_in-access"></span>
                    </div>
                    <div class="listRight" v-else>
                        <span class="listCheckT">请选择</span>
                        <span class="weui-cell__ft_in-access"></span>
                    </div>
                </div>
            </picker>
            <picker
                class="listItm"
                v-if="array"
                :disabled="disabled"
                @change="ethnicChange"
                :value="index2"
                range-key="name"
                :range="ethnicA"
            >
                <div class="listFlex main">
                    <div class="listLeft">民族</div>
                    <div class="listRight" v-if="index2&&ethnicA[index2]">
                        <span
                            class="listCheckT"
                            v-if="ethnicA[index2].name"
                        >{{ethnicA[index2].name}}</span>
                        <span class="weui-cell__ft_in-access"></span>
                    </div>
                    <div class="listRight" v-else>
                        <span class="listCheckT">请选择</span>
                        <span class="weui-cell__ft_in-access"></span>
                    </div>
                </div>
            </picker>
            <picker
                class="listItm"
                :disabled="disabled"
                v-if="array"
                @change="edulevelChange"
                :value="index3"
                range-key="name"
                :range="edulevelA"
            >
                <div class="listFlex main">
                    <div class="listLeft">文化程度</div>
                    <div class="listRight" v-if="index3&&edulevelA[index3]">
                        <span
                            class="listCheckT"
                            v-if="edulevelA[index3].name"
                        >{{edulevelA[index3].name}}</span>
                        <span class="weui-cell__ft_in-access"></span>
                    </div>
                    <div class="listRight" v-else>
                        <span class="listCheckT">请选择</span>
                        <span class="weui-cell__ft_in-access"></span>
                    </div>
                </div>
            </picker>
            <picker
                class="listItm"
                v-if="array"
                :disabled="disabled"
                @change="jobChange"
                :value="index4"
                range-key="name"
                :range="jobA"
            >
                <div class="listFlex main">
                    <div class="listLeft">职业</div>
                    <div class="listRight" v-if="index4&&jobA[index4]">
                        <span class="listCheckT" v-if="jobA[index4].name">{{jobA[index4].name}}</span>
                        <span class="weui-cell__ft_in-access"></span>
                    </div>
                    <div class="listRight" v-else>
                        <span class="listCheckT">请选择</span>
                        <span class="weui-cell__ft_in-access"></span>
                    </div>
                </div>
            </picker>
            <picker
                class="listItm"
                v-if="region"
                :disabled="disabled"
                @change="placeChange"
                mode="region"
                :value="region"
            >
                <div class="listFlex main">
                    <div class="listLeft">籍贯</div>
                    <div class="listRight" v-if="region[0]">
                        <span class="listCheckT" v-if="show">{{region[0]+','}}{{region[1]}}</span>
                        <span class="listCheckT" v-else>{{region[0]}}</span>
                        <span class="weui-cell__ft_in-access"></span>
                    </div>
                    <div class="listRight" v-else>
                        <span class="listCheckT">请选择</span>
                        <span class="weui-cell__ft_in-access"></span>
                    </div>
                </div>
            </picker>
            <picker
                class="listItm"
                v-if="array"
                :disabled="disabled"
                @change="nationTypeChange"
                :value="index5"
                range-key="name"
                :range="nationTypeA"
            >
                <div class="listFlex main">
                    <div class="listLeft">户籍类型</div>
                    <div class="listRight" v-if="index5&&nationTypeA[index5]">
                        <span
                            class="listCheckT"
                            v-if="nationTypeA[index5].name"
                        >{{nationTypeA[index5].name}}</span>
                        <span class="weui-cell__ft_in-access"></span>
                    </div>
                    <div class="listRight" v-else>
                        <span class="listCheckT">请选择</span>
                        <span class="weui-cell__ft_in-access"></span>
                    </div>
                </div>
            </picker>

            <picker
                class="listItm"
                :disabled="disabled"
                v-if="region2"
                @change="houseAChange"
                mode="region"
                :value="region2"
            >
                <div class="listFlex main">
                    <div class="listLeft">户口所在地</div>
                    <div class="listRight" v-if="region2[0]">
                        <span class="listCheckT" v-if="show2">{{region2[0]+','}}{{region2[1]}}</span>
                        <span class="listCheckT" v-else>{{region2[0]}}</span>
                        <span class="weui-cell__ft_in-access"></span>
                    </div>
                    <div class="listRight" v-else>
                        <span class="listCheckT">请选择</span>
                        <span class="weui-cell__ft_in-access"></span>
                    </div>
                </div>
            </picker>
            <picker
                class="listItm"
                :disabled="disabled"
                v-if="region1"
                @change="houseChange"
                mode="region"
                :value="region1"
            >
                <div class="listFlex main">
                    <div class="listLeft">现住址</div>
                    <div class="listRight" v-if="region1[0]">
                        <span class="listCheckT" v-if="show1">{{region1[0]+','}}{{region1[1]}}</span>
                        <span class="listCheckT" v-else>{{region1[0]}}</span>
                        <span class="weui-cell__ft_in-access"></span>
                    </div>
                    <div class="listRight" v-else>
                        <span class="listCheckT">请选择</span>
                        <span class="weui-cell__ft_in-access"></span>
                    </div>
                </div>
            </picker>

            <div class="listItm">
                <div class="listFlex main">
                    <div class="listLeft hiddenCom"></div>
                    <div class="listRight">
                        <span class="listCheckT">
                            <input
                                type="text"
                                :disabled="disabled"
                                placeholder-style="color: #999;"
                                class="inputStyle"
                                placeholder="请填写街道"
                                maxlength="10"
                                v-model="userInflist.gravidaInfo.addressStreet"
                                @input="inputT1"
                            />
                        </span>
                        <span class="weui-cell__ft_in-access hiddenCom"></span>
                    </div>
                </div>
            </div>
            <div class="listItm">
                <div class="listFlex main">
                    <div class="listLeft hiddenCom"></div>
                    <div class="listRight">
                        <span class="listCheckT">
                            <input
                                type="text"
                                :disabled="disabled"
                                placeholder-style="color: #999;"
                                class="inputStyle"
                                maxlength="10"
                                placeholder="请填写社区"
                                v-model="userInflist.gravidaInfo.currentCommunity"
                                @input="inputT1"
                            />
                        </span>
                        <span class="weui-cell__ft_in-access hiddenCom"></span>
                    </div>
                </div>
            </div>
            <div class="listItm">
                <div class="listFlex main">
                    <div class="listLeft hiddenCom"></div>
                    <div class="listRight">
                        <span class="listCheckT">
                            <input
                                type="text"
                                :disabled="disabled"
                                placeholder-style="color: #999;"
                                class="inputStyle"
                                placeholder="请填写管辖派出所"
                                maxlength="10"
                                v-model="userInflist.gravidaInfo.policeStation"
                                @input="inputT1"
                            />
                        </span>
                        <span class="weui-cell__ft_in-access hiddenCom"></span>
                    </div>
                </div>
            </div>
            <div class="listItm">
                <div class="listFlex main">
                    <div class="listLeft hiddenCom"></div>
                    <div class="listRight">
                        <span class="listCheckT">
                            <input
                                type="text"
                                :disabled="disabled"
                                placeholder-style="color: #999;"
                                class="inputStyle"
                                maxlength="20"
                                placeholder="请填写小区、单元、门牌号"
                                v-model="userInflist.gravidaInfo.address"
                                @input="inputT1"
                            />
                        </span>
                        <span class="weui-cell__ft_in-access hiddenCom"></span>
                    </div>
                </div>
            </div>
            <picker
                class="listItm"
                v-if="region3"
                @change="chanhouChange"
                mode="region"
                :disabled="disabled"
                :value="region3"
            >
                <div class="listFlex main">
                    <div class="listLeft">产后休养地</div>
                    <div class="listRight" v-if="region3[0]">
                        <span class="listCheckT" v-if="show3">{{region3[0]+','+region3[1]}}</span>
                        <span class="listCheckT" v-else>{{region3[0]}}</span>
                        <span class="weui-cell__ft_in-access"></span>
                    </div>
                    <div class="listRight" v-else>
                        <span class="listCheckT">请选择</span>
                        <span class="weui-cell__ft_in-access"></span>
                    </div>
                </div>
            </picker>
            <div class="listItm">
                <div class="listFlex main">
                    <div class="listLeft hiddenCom"></div>
                    <div class="listRight">
                        <span class="listCheckT">
                            <input
                                type="text"
                                :disabled="disabled"
                                placeholder-style="color: #999;"
                                class="inputStyle"
                                placeholder="请填写街道"
                                maxlength="10"
                                v-model="userInflist.pregnant.restStreet"
                                @input="inputT1"
                            />
                        </span>
                        <span class="weui-cell__ft_in-access hiddenCom"></span>
                    </div>
                </div>
            </div>
            <div class="listItm">
                <div class="listFlex main">
                    <div class="listLeft hiddenCom"></div>
                    <div class="listRight">
                        <span class="listCheckT">
                            <input
                                type="text"
                                :disabled="disabled"
                                placeholder-style="color: #999;"
                                class="inputStyle"
                                placeholder="请填写社区"
                                maxlength="10"
                                v-model="userInflist.pregnant.restCommunity"
                                @input="inputT1"
                            />
                        </span>
                        <span class="weui-cell__ft_in-access hiddenCom"></span>
                    </div>
                </div>
            </div>
            <div class="listItm">
                <div class="listFlex main">
                    <div class="listLeft hiddenCom"></div>
                    <div class="listRight">
                        <span class="listCheckT">
                            <input
                                type="text"
                                :disabled="disabled"
                                placeholder-style="color: #999;"
                                class="inputStyle"
                                maxlength="20"
                                placeholder="请填写小区、单元、门牌号"
                                v-model="userInflist.pregnant.restAddress"
                                @input="inputT1"
                            />
                        </span>
                        <span class="weui-cell__ft_in-access hiddenCom"></span>
                    </div>
                </div>
            </div>
            <div class="listItm">
                <div class="listFlex main">
                    <div class="listLeft">工作单位</div>
                    <div class="listRight">
                        <span class="listCheckT">
                            <input
                                type="text"
                                :disabled="disabled"
                                placeholder-style="color: #999;"
                                class="inputStyle"
                                maxlength="20"
                                placeholder="请填写"
                                v-model="userInflist.pregnant.workplace "
                            />
                        </span>
                    </div>
                </div>
            </div>
            <div class="listItm">
                <div class="listFlex main">
                    <div class="listLeft">
                        <span class="mustCheck__content">*</span>手机号码
                    </div>
                    <div class="listRight">
                        <span class="listCheckT">
                        {{userInflist.gravidaInfo.mobile}}
                            <!-- <input
                                type="text"
                                :disabled="disabled"
                                placeholder-style="color: #999;"
                                class="inputStyle"
                                maxlength="11"
                                placeholder="请填写"
                                v-model="userInflist.gravidaInfo.mobile"
                            /> -->
                        </span>
                    </div>
                </div>
            </div>
            <div class="listItm">
                <div class="listFlex main">
                    <div class="listLeft">结婚年龄(岁)</div>
                    <div class="listRight">
                        <span class="listCheckT">
                            <input
                                type="text"
                                :disabled="disabled"
                                maxlength="3"
                                placeholder-style="color: #999;"
                                class="inputStyle"
                                placeholder="请填写"
                                v-model.number="userInflist.pregnant.marriageAge "
                                @input="inputNumber"
                            />
                        </span>
                    </div>
                </div>
            </div>
            <picker
                class="listItm"
                v-if="array"
                :disabled="disabled"
                @change="payWayChange"
                :value="index6"
                range-key="name"
                :range="payWay"
            >
                <div class="listFlex main">
                    <div class="listLeft">医疗付费方式</div>
                    <div class="listRight" v-if="index6&&payWay[index6]">
                        <span class="listCheckT" v-if="payWay[index6].name">{{payWay[index6].name}}</span>
                        <span class="weui-cell__ft_in-access"></span>
                    </div>
                    <div class="listRight" v-else>
                        <span class="listCheckT">请选择</span>
                        <span class="weui-cell__ft_in-access"></span>
                    </div>
                </div>
            </picker>
            <div class="listItm">
                <div class="listFlex main">
                    <div class="listLeft" style="width:60%">政策（全面）两孩</div>
                    <div class="listRight" style="width:40%">
                        <span class="listCheckT">
                            <radio-group @change="radioChange">
                                <span class="listradio">
                                    <radio
                                        class="pink"
                                        :value="true"
                                        :disabled="disabled"
                                        :checked="twoChildren"
                                        color="#F75193"
                                    >是</radio>
                                </span>
                                <span class="listradio">
                                    <radio
                                        class="pink"
                                        :value="false"
                                        :disabled="disabled"
                                        :checked="!twoChildren"
                                        color="#F75193"
                                    >否</radio>
                                </span>
                            </radio-group>
                        </span>
                    </div>
                </div>
            </div>
            <picker
                :disabled="disabled"
                :end="endTime"
                class="listItm"
                mode="date"
                @change="bindDateChange"
            >
                <div class="listFlex main">
                    <div class="listLeft">
                        <span class="mustCheck__content">*</span> 末次月经时间
                    </div>
                    <div class="listRight" v-if="userInflist.pregnant.lastMenstrual">
                        <span
                            class="listCheckT"
                        >{{ issubstring(userInflist.pregnant.lastMenstrual) }}</span>
                        <span class="weui-cell__ft_in-access"></span>
                    </div>
                    <div class="listRight" v-else>
                        <span class="listCheckT">请选择</span>
                        <span class="weui-cell__ft_in-access"></span>
                    </div>
                </div>
            </picker>
            <div class="listFlex main">
                <div class="listLeft">
                    <span class="mustCheck__content">*</span> 预产期
                </div>
                <div class="listRight" v-if="lastyuejin">
                    <span class="listCheckT">{{ childbirthTimeA }}</span>
                </div>
            </div>
            <husband
                v-if="husbandInfoShow"
                ref="husbandInfo"
                :newlybuild="newlybuild"
                :array="array"
                :endTime="endTime"
                :userInflist="userInflist"
                :disabled="disabled"
            />
        </div>
        <div class="btmItm">温馨提示：该数据将用于产检建册，严格保密。</div>
        <div class="btn">
            <div class="saveBtn" @click="handleClick">
                <span>下一步</span>
            </div>
        </div>
    </div>
</template>
<script>
import husband from "pages/putOnRecord/components/husband.vue";
export default {
    components: {
        husband
    },
    data() {
        return {
            endTime: "",
            twoChildren:false,
            hospital: "",
            childbirthTimeA: "",
            lastyuejin: "1",
            bottom: null,
            index0: "",
            index1: "",
            index2: "",
            index3: "",
            index4: "",
            index5: "",
            index6: "",

            // 1：选择列表
            documentType: [],
            nationality: [], // 国籍
            ethnicA: [],
            edulevelA: [],
            jobA: [],
            nationTypeA: [],
            payWay: [], //医疗付费方式
            region: ["", "", ""], // 籍贯
            show: true,
            region1: ["", "", ""], //现住地址
            show1: true,
            region2: ["", "", ""], // 户口所在地
            show2: true,
            region3: ["", "", ""], // 产后休养地
            show3: true,
            husbandInfoShow: false,
            userInf: {
                chineseName: "",
                mobile: "", //手机号码
                idType: 1, // 证件类型
                idNumber: null, // 证件号码
                birthday: "", //出生日期
                nationality: 1, // 国籍
                ethnic: 1, // 民族
                education: null, // 文化程度
                career: null, // 职业
                householdRegistrationType: null, // 户籍类型
                // 籍贯
                province: null, // 省
                cities: null, // 市
                // 户口所在地
                householdProvince: null, // 省
                householdCity: null, // 市
                // 现住址
                addressProvince: null, // 省
                addressCity: null, // 市
                addressArea: "", //区
                address: null, // 详细
                policeStation: "", //派出所
                lastMenstrual: "", //末次月经时间
                currentCommunity: "", //社区
                restAddress: "", //产后修养地（详细地址） ,
                restArea: "", // 产后修养地（区） ,
                restCity: "", // 产后修养地（市） ,
                restCommunity: "", // 产后修养地所属社区 ,
                restProvince: "", // 产后修养地（省份） ,
                restStreet: "", // 产后修养地（街道） ,
                workplace: "", //工作单位
                marriageAge: "", //结婚年龄
                twoChildren: "" //政策（全面）两孩
            },
            userInflist: {
                gravidaInfo: {
                    account: "",
                    // 现住址
                    address: "", // 详细
                    addressArea: "", //区
                    addressCity: "", // 市
                    addressProvince: "", // 省
                    addressStreet: "", //街道
                    currentCommunity: "", //社区
                    birthday: "", //出生日期
                    blood: "",
                    career: "", //职业
                    chineseName: "", //孕妇姓名
                    cities: "", //籍贯市
                    education: "", //文化程度

                    ethnic: "", //民族
                    household: "",
                    householdCity: "", //户口所在地市
                    householdProvince: "", //户口所在地省
                    householdRegistrationType: "", //户籍类型

                    idNumber: "", //证件号码
                    idType: "", //证件类型

                    mobile: "", //手机号码

                    nationality: 1, //国籍

                    policeStation: "", //派出所
                    province: "" //籍贯省
                },
                husbandInfo: {
                    birthday: "",
                    ethnic: "",
                    sex: "",
                    career: "", //职业
                    chineseName: "", //丈夫姓名
                    cities: "", //籍贯市
                    disgustingHabit: "", //不良嗜好
                    hospitalId: "",
                    education: "", //文化程度
                    ethnic: "", //民族
                    householdCity: "", //户口所在市
                    householdProvince: "", //户口所在省
                    householdRegistrationType: "", //户籍类型
                    idNumber: "", //证件号码
                    idType: "", //证件类型
                    mobile: "", //手机号码
                    nationality: "", //国籍
                    province: "", //籍贯省
                    workplace: "" //工作单位
                },
                pregnant: {
                    // bloodPressureService: null,
                    // bloodSugarService: true,
                    childbirthTime: null,
                    // contactMobile: "",
                    // createId: "",
                    // createTime: "",
                    // departmentId: "",
                    // departmentName: "",
                    // disgustingHabit: null,
                    // doctorId: "",
                    // doctorName: "",
                    // emergencyContact: "",
                    // establishDay: null,
                    // establishWeek: null,
                    // frontBmi: null,
                    // frontHeight: null,
                    // frontWeight: null,
                    // hospitalAddress: null,
                    hospitalId: "", //医院id
                    hospitalName: "", //医院名字
                    // husbandId: null,
                    // husbandWorkplace: null,
                    // id: "",
                    lastMenstrual: "", //末次月经时间
                    marriageAge: null, //结婚年龄
                    // modifyId: "",
                    // modifyTime: "",
                    // no: null,
                    payWay: null, //医疗付费方式
                    // pregnancyTimes: null,
                    relationship: null, //关系
                    //产后休养
                    restAddress: null, //产后修养地（详细地址）
                    restArea: null, //产后修养地（区）
                    restCity: null, // 产后修养地（市）
                    restCommunity: null, // 产后修养地所属社区
                    restProvince: null, // 产后修养地（省份）
                    restStreet: null, // 产后修养地（街道）
                    // reviewId: null,
                    // reviewTime: null,
                    // riskLevel: 2,
                    // source: null,
                    // state: 3,
                    status: 1,
                    // step: 4,
                    twoChildren: "", //政策全面两孩
                    // userId: "",
                    workplace: null //工作单位
                }
            },
            gravidaInfo: {}
        };
    },
    props: {
        array: {
            type: Object,
            required: true
        },
        disabled: {
            type: Boolean
        },
        newlybuild: {
            type: String
        },
        id: {
            type: String
        }
    },
    mounted() {
        var _this = this;
        _this.documentType = _this.array.documentType;
        _this.nationality = _this.array.nationality;
        _this.ethnicA = _this.array.ethnicA;
        _this.edulevelA = _this.array.edulevelA;
        _this.jobA = _this.array.jobA;
        _this.nationTypeA = _this.array.nationTypeA;
        _this.payWay = _this.array.payWay;
        _this.husbandInfoShow = false;
        _this.getbottom();
        if(_this.newlybuild=='新建'){
            _this.hospital = uni.getStorageSync("hospital").name;
        }
        _this.endTime = _this.gettimes();
    },

    methods: {
        checkField(name,field,vaule){
             
            const reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
            if (!reg.test(vaule)) {
                return uni.showToast({
                    title: "证件号格式错误！",
                    icon: "none"
                });
            }  
            //字段验证
             var _this = this;
             var data={
                 field:field,
                 vaule:vaule,
             }
            _this.$ajaxs
                .get("/mobile/v1/pregnant/checkField",data)
                .then(res => {
                    if (res.content) {
                        if(_this.userInflist.gravidaInfo.id!=res.content.id){
                            return uni.showToast({
                                title: name+"已存在",
                                icon: "none"
                            });
                        }
                    }
                })
                .catch(err => reject(err));
        },
        
        gettimes() {
            var dd = new Date();
            dd.setDate(dd.getDate()); //获取AddDayCount天后的日期
            var y = dd.getFullYear();
            var m =
                dd.getMonth() + 1 < 10
                    ? "0" + (dd.getMonth() + 1)
                    : dd.getMonth() + 1; //获取当前月份的日期，不足10补0
            var d = dd.getDate() < 10 ? "0" + dd.getDate() : dd.getDate(); //获取当前几号，不足10补0
            return y + "-" + m + "-" + d;
        },
        getbottom() {
            var _this = this;
            _this.$ajaxs
                .get("/mobile/v1/pregnant/getGpregnant")
                .then(res => {
                    if (res.content) {
                        _this.getGpregnantMiniApp();
                    } else {
                        _this.getInf();
                    }
                })
                .catch(err => reject(err));
        },
        issubstring(itm) {
            if (itm) {
                return itm.substring(0, 10);
            } else {
                return "";
            }
        },
         inputNumber(e){
                var _this = this;
                 if (e.detail.value) {
                    const reg = /^[+]{0,1}(\d+)$/;
                    if (!reg.test(e.detail.value)) {
                        return uni.showToast({
                            title: "请输入整数",
                            icon: "none"
                        });
                    }
                }
            // 
        },
        handleClick() {
            var _this = this;
            if(_this.disabled){
                 return _this.$emit("previous", 2);
            }
            var hospital = uni.getStorageSync("hospital");
            _this.userInflist.pregnant.relationship = "1"; //关系
            _this.userInflist.pregnant.source = "1";
             if(_this.newlybuild=='新建'){
            _this.userInflist.pregnant.hospitalId = hospital.id; //医院id
            _this.userInflist.pregnant.hospitalName = hospital.name; //医院名字
            }
           
            _this.userInflist.husbandInfo = _this.$refs.husbandInfo.getfrom();
             if(_this.newlybuild=='新建'){
                _this.userInflist.husbandInfo.hospitalId = hospital.id; //医院id
             }
            if (_this.userInflist.gravidaInfo.chineseName) {
                const reg = new RegExp(
                    "^([\u4E00-\uFA29]|[\uE7C7-\uE7F3]|[a-zA-Z0-9])*$"
                );
                if (!reg.test(_this.userInflist.gravidaInfo.chineseName)) {
                    return uni.showToast({
                        title: "请输入正确的孕妇姓名！",
                        icon: "none"
                    });
                }
            } else {
                return uni.showToast({
                    title: "请输入孕妇姓名！",
                    icon: "none"
                });
            }
            if (!_this.userInflist.gravidaInfo.idType) {
                return uni.showToast({
                    title: "请选择证件类型！",
                    icon: "none"
                });
            }
            if (_this.userInflist.gravidaInfo.idNumber) {
                if (_this.userInflist.gravidaInfo.idType == "1") {
                    const reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
                    if (!reg.test(_this.userInflist.gravidaInfo.idNumber)) {
                        return uni.showToast({
                            title: "证件号格式错误！",
                            icon: "none"
                        });
                    }
                }
            } else {
                return uni.showToast({
                    title: "请输入证件号码！",
                    icon: "none"
                });
            }
            if (!_this.userInflist.gravidaInfo.birthday) {
                return uni.showToast({
                    title: "请选择出生日期！",
                    icon: "none"
                });
            }
            if (!_this.userInflist.pregnant.lastMenstrual) {
                return uni.showToast({
                    title: "请选择末次月经时间！",
                    icon: "none"
                });
            }
            if (_this.userInflist.gravidaInfo.mobile) {
                const reg = /^1[0-9][0-9]\d{8}$/;
                if (!reg.test(_this.userInflist.gravidaInfo.mobile)) {
                    return uni.showToast({
                        title: "手机号格式错误！",
                        icon: "none"
                    });
                }
            } else {
                return uni.showToast({
                    title: "请输入手机号码！",
                    icon: "none"
                });
            }
            if (_this.userInflist.husbandInfo.chineseName) {
                const reg = new RegExp(
                    "^([\u4E00-\uFA29]|[\uE7C7-\uE7F3]|[a-zA-Z0-9])*$"
                );
                if (!reg.test(_this.userInflist.husbandInfo.chineseName)) {
                    return uni.showToast({
                        title: "请输入正确的丈夫姓名！",
                        icon: "none"
                    });
                }
            } else {
                return uni.showToast({
                    title: "请输入丈夫姓名！",
                    icon: "none"
                });
            }
            if (!_this.userInflist.husbandInfo.idType) {
                return uni.showToast({
                    title: "请选择丈夫证件类型！",
                    icon: "none"
                });
            }
            if (_this.userInflist.husbandInfo.idNumber) {
                if (_this.userInflist.husbandInfo.idType == "1") {
                    const reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
                    if (!reg.test(_this.userInflist.husbandInfo.idNumber)) {
                        return uni.showToast({
                            title: "丈夫证件号格式错误！",
                            icon: "none"
                        });
                    }
                }
            } else {
                return uni.showToast({
                    title: "请输入丈夫证件号码！",
                    icon: "none"
                });
            }
            if (_this.userInflist.husbandInfo.mobile) {
                const reg = /^1[0-9][0-9]\d{8}$/;
                if (!reg.test(_this.userInflist.husbandInfo.mobile)) {
                    return uni.showToast({
                        title: "丈夫手机号格式错误！",
                        icon: "none"
                    });
                }
            } else {
                return uni.showToast({
                    title: "请输入丈夫手机号码！",
                    icon: "none"
                });
            }
            if(_this.userInflist.pregnant.marriageAge){
                 const reg = /^[+]{0,1}(\d+)$/;
                    if (!reg.test(_this.userInflist.pregnant.marriageAge)) {
                        return uni.showToast({
                            title: "结婚年龄请输入整数",
                            icon: "none"
                        });
                    }
            }
            var disgustingHabit=JSON.parse(_this.userInflist.husbandInfo.disgustingHabit)
           if(disgustingHabit.smoking){
                 const reg = /^[+]{0,1}(\d+)$/;
                    if (!reg.test(disgustingHabit.smoking)) {
                        return uni.showToast({
                            title: "吸烟量请输入整数",
                            icon: "none"
                        });
                    }
            }
            if(disgustingHabit.drinking){
                 const reg = /^[+]{0,1}(\d+)$/;
                    if (!reg.test(disgustingHabit.drinking)) {
                        return uni.showToast({
                            title: "饮酒量请输入整数",
                            icon: "none"
                        });
                    }
            }
            if(disgustingHabit.otherHobbies){
                const reg = new RegExp(
                    "^([\u4E00-\uFA29]|[\uE7C7-\uE7F3])*$"
                );
                    if (!reg.test(disgustingHabit.otherHobbies)) {
                        return uni.showToast({
                            title: "其他嗜好请输入汉字",
                            icon: "none"
                        });
                    }
            }
            if (_this.userInflist.pregnant.lastMenstrual&&_this.userInflist.pregnant.lastMenstrual.length < 11) {
                _this.userInflist.pregnant.lastMenstrual =
                    _this.userInflist.pregnant.lastMenstrual + " 00:00:00";
            }
            if (_this.userInflist.gravidaInfo.birthday&&_this.userInflist.gravidaInfo.birthday.length < 11) {
                _this.userInflist.gravidaInfo.birthday =
                    _this.userInflist.gravidaInfo.birthday + " 00:00:00";
            }
            if (_this.userInflist.husbandInfo.birthday&&_this.userInflist.husbandInfo.birthday.length < 11) {
                _this.userInflist.husbandInfo.birthday =
                    _this.userInflist.husbandInfo.birthday + " 00:00:00";
            }
            // if(){

            // }
            _this.getfrom(_this.userInflist);
        },
        getfrom(data) {
            var _this = this;
            _this.$ajaxs
                .post("/mobile/v1/pregnant/saveInnerMiniApp", data)
                .then(res => {
                    if (res.status == 200) {
                        if(res.content.statusCode=='4004'){
                            return uni.showToast({
                                title: res.content.statusMessage,
                                icon: "none"
                            });
                        }  
                        uni.setStorage({
                            //存储到本地
                            key: "pregnantId",
                            data: res.content.pregnantId
                        });
                        _this.$emit("previous", 2);
                        _this.$emit("neraasdas");
                    } else {
                        uni.showToast({
                            title: res.message,
                            icon: "none"
                        });
                    }
                })
                .catch(err => reject(err));
        },
        radioChange(e) {
            // this.twoChildren = e.detail.value;
            //  console.log(e.detail.value,this.twoChildren);
            this.userInflist.pregnant.twoChildren = e.detail.value;
        },
        getGpregnantMiniApp(id) {
            var _this = this;
            _this.$ajaxs
                .get("/mobile/v1/pregnant/getGpregnantMiniApp", {
                    id: uni.getStorageSync("pregnantId")
                })
                .then(res => {
                    if (res.status == 200 && _this.array) {
                        _this.userInflist = res.content;
                        if(_this.userInflist.pregnant.status==1&&_this.userInflist.pregnant.state==3){
                            if(_this.newlybuild=='新建'){
                                _this.userInflist.pregnant.id=null;
                                _this.userInflist.pregnant.state=1;
                                _this.userInflist.pregnant.status=0;
                                _this.userInflist.pregnant.step=1;
                                _this.userInflist.pregnant.createTime='';
                                _this.userInflist.pregnant.lastMenstrual='';
                            }
                        }
                        console.log( _this.userInflist)
                        if(_this.newlybuild!='新建'){
                            _this.hospital = _this.userInflist.pregnant.hospitalName;
                        }
                        _this.husbandInfoShow = true;
                        _this.$emit(
                            "getStatus",
                            _this.userInflist.pregnant.step
                        );
                        if (_this.userInflist.pregnant.lastMenstrual) {
                            _this.childbirthTimeA = _this.getCB(
                                _this.userInflist.pregnant.lastMenstrual
                            );
                        }
                        if (_this.userInflist.gravidaInfo.idType) {
                            _this.index0 =
                                _this.userInflist.gravidaInfo.idType - 1 + "";
                        }
                        if (_this.userInflist.gravidaInfo.nationality) {
                            _this.index1 =
                                _this.userInflist.gravidaInfo.nationality -
                                1 +
                                "";
                        }
                        if (_this.userInflist.gravidaInfo.ethnic) {
                            _this.index2 =
                                _this.userInflist.gravidaInfo.ethnic - 1 + "";
                        }
                        if (_this.userInflist.gravidaInfo.education) {
                            _this.index3 =
                                _this.userInflist.gravidaInfo.education -
                                1 +
                                "";
                        }
                        if (_this.userInflist.gravidaInfo.career) {
                            _this.index4 =
                                _this.userInflist.gravidaInfo.career - 1 + "";
                        }
                        if (
                            _this.userInflist.gravidaInfo.province &&
                            _this.userInflist.gravidaInfo.cities
                        ) {
                            _this.region = [
                                _this.userInflist.gravidaInfo.province,
                                _this.userInflist.gravidaInfo.cities
                            ];
                            if (
                                _this.userInflist.gravidaInfo.province ==
                                _this.userInflist.gravidaInfo.cities
                            ) {
                                _this.show = false;
                            } else {
                                _this.show = true;
                            }
                        }
                        if (
                            _this.userInflist.gravidaInfo
                                .householdRegistrationType
                        ) {
                            _this.index5 =
                                _this.userInflist.gravidaInfo
                                    .householdRegistrationType -
                                1 +
                                "";
                        }

                        if (_this.userInflist.pregnant.payWay) {
                            _this.index6 =
                                _this.userInflist.pregnant.payWay - 1 + "";
                        }
                        if (
                            _this.userInflist.gravidaInfo.householdProvince &&
                            _this.userInflist.gravidaInfo.householdCity
                        ) {
                            _this.region2 = [
                                _this.userInflist.gravidaInfo.householdProvince,
                                _this.userInflist.gravidaInfo.householdCity
                            ];
                            if (
                                _this.userInflist.gravidaInfo
                                    .householdProvince ==
                                _this.userInflist.gravidaInfo.householdCity
                            ) {
                                _this.show2 = false;
                            } else {
                                _this.show2 = true;
                            }
                        }
                        if (
                            _this.userInflist.gravidaInfo.addressProvince &&
                            _this.userInflist.gravidaInfo.addressCity
                        ) {
                            _this.region1 = [
                                _this.userInflist.gravidaInfo.addressProvince,
                                _this.userInflist.gravidaInfo.addressCity,
                                _this.userInflist.gravidaInfo.addressArea
                            ];
                            if (
                                _this.userInflist.gravidaInfo.addressProvince ==
                                _this.userInflist.gravidaInfo.addressCity
                            ) {
                                _this.show1 = false;
                            } else {
                                _this.show1 = true;
                            }
                        }
                        if (
                            _this.userInflist.pregnant.restProvince &&
                            _this.userInflist.pregnant.restCity
                        ) {
                            _this.region3 = [
                                _this.userInflist.pregnant.restProvince,
                                _this.userInflist.pregnant.restCity,
                                _this.userInflist.pregnant.restArea
                            ];
                            if (
                                _this.userInflist.pregnant.restProvince ==
                                _this.userInflist.pregnant.restCity
                            ) {
                                _this.show3 = false;
                            } else {
                                _this.show3 = true;
                            }
                        }
                        _this.twoChildren=_this.userInflist.pregnant.twoChildren
                    } else {
                        uni.showToast({
                            title: "网路不畅~",
                            icon: "none"
                        });
                    }
                })
                .catch(err => reject(err));
        },
        getInf() {
            // console.log('基本信息')
            var _this = this;
            _this.$ajaxs
                .get("/mobile/v1/users/getUserInfo")
                .then(res => {
                    if (res.status == 200 && _this.array) {
                        var userInf = res.content;
                        _this.index0 = "0"; //身份证
                        _this.index1 = "0"; //国籍
                        _this.index2 = "0"; //民族
                        userInf.idType = "1"; //身份证
                        userInf.sex = "2"; //性别女
                        userInf.nationality = "1"; //国籍
                        userInf.ethnic = "1"; //民族
                        _this.userInflist.gravidaInfo = userInf;
                        _this.userInflist.gravidaInfo.addressProvince=uni.getStorageSync("hospital").province; //现住址省
                        _this.userInflist.gravidaInfo.addressCity=uni.getStorageSync("hospital").city; //现住址市
                        _this.userInflist.pregnant.restProvince=uni.getStorageSync("hospital").province; //现住址省
                        _this.userInflist.pregnant.restCity=uni.getStorageSync("hospital").city; //现住址市
                        _this.region3 = [
                            _this.userInflist.pregnant.restProvince,
                            _this.userInflist.pregnant.restCity,
                            ""
                        ];
                        if (
                            _this.userInflist.pregnant.restProvince ==
                            _this.userInflist.pregnant.restCity
                        ) {
                            _this.show3 = false;
                        } else {
                            _this.show3 = true;
                        }
                        _this.region1 = [
                            _this.userInflist.gravidaInfo.addressProvince,
                            _this.userInflist.gravidaInfo.addressCity,
                            ''
                        ];
                        if (
                            _this.userInflist.gravidaInfo.addressProvince ==
                            _this.userInflist.gravidaInfo.addressCity
                        ) {
                            _this.show1 = false;
                        } else {
                            _this.show1 = true;
                        }
                        _this.husbandInfoShow = true;
                    } else {
                        uni.showToast({
                            title: "网路不畅~",
                            icon: "none"
                        });
                    }
                })
                .catch(err => reject(err));
        },

        inputT3(e) {
            var _this = this;
            this.userInflist.gravidaInfo.idNumber = e.detail.value; // 证件号码
            if (this.userInflist.gravidaInfo.idType == 1) {
                this.userInflist.gravidaInfo.birthday = this.getBirthdayFromIdCard(
                    this.userInflist.gravidaInfo.idNumber
                );
                if(!_this.userInflist.gravidaInfo.idNumber) return
                _this.checkField('孕妇证件号码','idNumber',_this.userInflist.gravidaInfo.idNumber)
            }
        },
        getBirthdayFromIdCard(idCard) {
            var birthday = "";
            if (idCard != null && idCard != "") {
                if (idCard.length == 15) {
                    birthday = "19" + idCard.substr(6, 6);
                } else if (idCard.length == 18) {
                    birthday = idCard.substr(6, 8);
                }
                birthday = birthday.replace(/(.{4})(.{2})/, "$1-$2-");
            }

            return birthday;
        },
        inputT1(e) {},
        cartChange(e) {
            // 证件类型
            this.index0 = e.target.value;
            this.userInflist.gravidaInfo.idType = e.target.value - 0 + 1 + "";
        },
        nationChange(e) {
            // 国籍
            this.index1 = e.target.value;
            this.userInflist.gravidaInfo.nationality =
                e.target.value - 0 + 1 + "";
        },
        ethnicChange(e) {
            this.index2 = e.target.value;
            this.userInflist.gravidaInfo.ethnic = e.target.value - 0 + 1 + "";
        },
        edulevelChange(e) {
            this.index3 = e.target.value;
            this.userInflist.gravidaInfo.education =
                e.target.value - 0 + 1 + "";
        },
        jobChange(e) {
            this.index4 = e.target.value;
            this.userInflist.gravidaInfo.career = e.target.value - 0 + 1 + "";
        },
        placeChange(e) {
            this.region = e.target.value;
            this.userInflist.gravidaInfo.province = e.target.value[0];
            this.userInflist.gravidaInfo.cities = e.target.value[1];
            if (
                this.userInflist.gravidaInfo.province ==
                this.userInflist.gravidaInfo.cities
            ) {
                this.show = false;
            } else {
                this.show = true;
            }
        },
        houseChange(e) {
            this.region1 = e.target.value;
            this.userInflist.gravidaInfo.addressProvince = e.target.value[0];
            this.userInflist.gravidaInfo.addressCity = e.target.value[1];
            this.userInflist.gravidaInfo.addressArea = e.target.value[2];
            if (
                this.userInflist.gravidaInfo.addressProvince ==
                this.userInflist.gravidaInfo.addressCity
            ) {
                this.show1 = false;
            } else {
                this.show1 = true;
            }
        },
        houseAChange(e) {
            this.region2 = e.target.value;
            this.userInflist.gravidaInfo.householdProvince = e.target.value[0];
            this.userInflist.gravidaInfo.householdCity = e.target.value[1];
            if (
                this.userInflist.gravidaInfo.householdProvince ==
                this.userInflist.gravidaInfo.householdCity
            ) {
                this.show2 = false;
            } else {
                this.show2 = true;
            }
        },
        bindDateChange(e) {
            var _this = this;
            _this.$set(
                _this.userInflist.pregnant,
                "lastMenstrual",
                e.detail.value
            );
            _this.childbirthTimeA = _this.getCB(e.detail.value);

            var str = _this.childbirthTimeA; // 日期字符串

            str = str.replace(/-/g, "/"); // 将-替换成/，因为下面这个构造函数只支持/分隔的日期字符串

            var date = new Date(str); // 构造一个日期型数据，值为传入的字符串
            var time = date.getTime();
            _this.$set(_this.userInflist.pregnant, "childbirthTime", time);
        },
        birthdayChange(e) {
            var _this = this;
            this.$set(
                _this.userInflist.gravidaInfo,
                "birthday",
                e.detail.value
            );
        },
        getCB(time0) {
            // 280天
            if (time0) {
                var time = time0.replace(/-/g, "/");
                var dd = new Date(time);
                var AddDayCount = 280;
                dd.setDate(dd.getDate() + AddDayCount); //获取AddDayCount天后的日期
                var y = dd.getFullYear();
                var m =
                    dd.getMonth() + 1 < 10
                        ? "0" + (dd.getMonth() + 1)
                        : dd.getMonth() + 1; //获取当前月份的日期，不足10补0
                var d = dd.getDate() < 10 ? "0" + dd.getDate() : dd.getDate(); //获取当前几号，不足10补0
                return y + "-" + m + "-" + d;
            } else {
                return "--";
            }
        },
        chanhouChange(e) {
            this.region3 = e.target.value;
            this.userInflist.pregnant.restProvince = e.target.value[0];
            this.userInflist.pregnant.restCity = e.target.value[1];
            this.userInflist.pregnant.restArea = e.target.value[2];
            if (
                this.userInflist.pregnant.restProvince ==
                this.userInflist.pregnant.restCity
            ) {
                this.show3 = false;
            } else {
                this.show3 = true;
            }
            // restAddress:'',//产后修养地（详细地址） ,
            // restArea:'',// 产后修养地（区） ,
            // restCity:'',// 产后修养地（市） ,
            // restCommunity:'',// 产后修养地所属社区 ,
            // restProvince:'',// 产后修养地（省份） ,
            // restStreet:'',// 产后修养地（街道） ,
        },
        nationTypeChange(e) {
            this.index5 = e.target.value;
            this.userInflist.gravidaInfo.householdRegistrationType =
                e.target.value - 0 + 1 + "";
        },
        payWayChange(e) {
            this.index6 = e.target.value;
            this.userInflist.pregnant.payWay = e.target.value - 0 + 1 + "";
        },
        //排序方法
        compare(property) {
            return function(a, b) {
                var value1 = a[property];
                var value2 = b[property];
                return value1 - value2;
            };
        }
    }
};
</script>
<style scoped>
.btn {
    width: 100%;
    height: 64px;
    display: flex;
    justify-content: space-between;
}

.saveBtn {
    height: 80upx;
    width: 100%;
    text-align: center;
    line-height: 80upx;
    border: 1px solid #fa4d93;
    border-radius: 40upx;
    color: #fa4d93;
    font-size: 32upx;
    background: #fff;
    margin: 0 40upx;
}
</style>